<template>
    <div class="cart-control">
        <transition name="move-minus">
            <div v-show="food.count>0" class="minus" @click.stop.prevent="$emit('minusAction', food)">
                <span class="inner icon-remove_circle_outline"></span>
            </div>
        </transition>
        <transition name="move-count">
            <div v-show="food.count>0" class="count">{{food.count}}</div>
        </transition>
        <div class="add" @click.stop.prevent="addAction">
            <span class="inner icon-add_circle"></span>
        </div>
    </div>
</template>

<script>
import { eventBus } from '../common/event-bus.js'
export default {
    props: {
        food: {
            type: Object
        }
    },
    methods: {
        addAction(e) {
            if (!event._constructed) {
                return
            }
            this.$emit('addAction', this.food)
            this.$nextTick(() => {
                eventBus.$emit('addCart', e.target)
            })
        }
    }
}
</script>

<style lang="less">
.cart-control {
    display: flex;
    color: rgb(0, 160, 220);
    font-size: 0;
    .inner {
        font-size: 24px;
        line-height: 24px;
    }
    display: flex;
    .count {
        display: inline-block;
        width: 24px;
        height: 24px;
        text-align: center;
        line-height: 24px;
        font-size: 10px;
        color: rgb(147, 153, 159);
    }
    .minus {
        &.move-minus-enter-active,
        &.move-minus-leave-active {
            transition: all 0.5s ease;
        }
        &.move-minus-enter,
        &.move-minus-leave-to {
            opacity: 0;
            transform: translate3d(24px, 0, 0) rotate(180deg);
        }
    }
    .count {
        &.move-count-enter-active,
        &.move-count-leave-active {
            transition: all 0.5s ease;
        }
        &.move-count-enter,
        &.move-count-leave-to {
            opacity: 0;
            transform: translate3d(24px, 0, 0);
        }
    }
}
</style>
